package demo.afeng.fastcrud.controller;

import demo.afeng.fastcrud.entity.User;
import demo.afeng.fastcrud.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2020-09-05 16:56:23
 */
@RestController
public class UserController {
    
    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     */
    @RequestMapping(value = "user", method = RequestMethod.GET)
    public User selectOne(Integer id) {
        return this.userService.queryById(id);
    }
    /**
     * 范围查找
     */
    @RequestMapping(value = "user",method = RequestMethod.GET,params = "select=limit")
    public List<User> selectAll(int offset, int limit) {
        return this.userService.queryAllByLimit(offset,limit);
    }
    /**
     * 新增
     */
    @RequestMapping(value = "user", method = RequestMethod.POST)
    public User create(@RequestBody User user) {
        return this.userService.insert(user);
    }
    /**
     * 更新
     */
    @RequestMapping(value = "user", method = RequestMethod.PUT)
    public User update(@RequestBody User user) {
        return this.userService.update(user);
    }
    /**
     * 通过id删除
     */
    @RequestMapping(value = "user", method = RequestMethod.DELETE)
    public boolean deleteOne(Integer id) {
        return this.userService.deleteById(id);
    }

}